﻿using System;
using System.Xml.Serialization;

namespace InstanceConfigurer
{
	[XmlRoot("applicationSettings")]
	[Serializable]
	public class ApplicationSettings
	{
		/// <summary>
		/// AzureDataConnectionString Property
		/// </summary>
		/// <remarks>The application default connection string to table storage.</remarks>
		public string AzureDataConnectionString { get; set; }

		/// <summary>
		/// ConfigurationDALTableName Property
		/// </summary>
		/// <remarks>The application exposes information to the Instance Controller when it 
		/// requests connection information to access table storage.  This is account specific 
		/// data and is sensitive.</remarks>
		public string ConfigurationDALTableName { get; set; }

		/// <summary>
		/// ConfigurationPartitionKey Property
		/// </summary>
		/// <remarks>This is the one and only configuration setting record.</remarks>
		/// <value>InstanceMonitorConfiguration</value>
		public string ConfigurationPartitionKey { get; set; }

		/// <summary>
		/// ConfigurationRoleRowKey Property
		/// </summary>
		/// <remarks>This is the one and only row in the configuration.  The row key must 
		/// be your web role name.</remarks>
		/// <value>WebRoleNameHere</value>
		public string ConfigurationRoleRowKey { get; set; }

		/// <summary>
		/// CounterSettingsTableName Property
		/// </summary>
		/// <remarks>The configuration table contains application specific setting for 
		/// the Instance Contorller.</remarks>
		/// <value>ConfigurationTable</value>
		public string CounterSettingsTableName { get; set; }

		/// <summary>
		/// PerformanceCountersConnectionString Property
		/// </summary>
		public string PerformanceCountersConnectionString { get; set; }

		/// <summary>
		/// PerformanceCountersPartitionKey Property
		/// </summary>
		public string PerformanceCountersPartitionKey { get; set; }

		/// <summary>
		/// StateMachineConnectionString Property
		/// </summary>
		public string StateMachineConnectionString { get; set; }

		/// <summary>
		/// StateMachineTableName Property
		/// </summary>
		public string StateMachineTableName { get; set; }

		/// <summary>
		/// StateMachinePartitionKey Property
		/// </summary>
		public string StateMachinePartitionKey { get; set; }

		/// <summary>
		/// InstancesConnectionString Property
		/// </summary>
		public string InstancesConnectionString { get; set; }

		/// <summary>
		/// InstancesTableName Property
		/// </summary>
		public string InstancesTableName { get; set; }

		/// <summary>
		/// InstancesPartitionKey Property
		/// </summary>
		public string InstancesPartitionKey { get; set; }

		/// <summary>
		/// WADiagnosticConnectionString Property
		/// </summary>
		/// <remarks>This setting is the setting that matches the setting in the Azure 
		/// service configuration file for the diagnostics automatically collected by Azure.</remarks>
		/// <value>Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString</value>
		public string WADiagnosticConnectionString { get; set; }

		/// <summary>
		/// WADPerformanceCountersDALTableName Property
		/// </summary>
		/// <remarks>This table is created by Azure Diagnostics for the performance 
		/// counters.  There are others for other diagnostic data.</remarks>
		/// <value>WADPerformanceCounters</value>
		public string WADPerformanceCountersDALTableName { get; set; }

		/// <summary>
		/// ControlledRoleName Property
		/// </summary>
		public string ControlledRoleName { get; set; }

		/// <summary>
		/// SubscriptionID Property
		/// </summary>
		public string SubscriptionID { get; set; }

		/// <summary>
		/// ThumbPrint Property
		/// </summary>
		public string ThumbPrint { get; set; }

		/// <summary>
		/// MaxInstances Property
		/// </summary>
		public int MaxInstances { get; set; }

		/// <summary>
		/// MinInstances Property
		/// </summary>
		public int MinInstances { get; set; }

		public void SetValue(string settingName, string value)
		{
			switch (settingName)
			{
				case "AzureDataConnectionString":
					AzureDataConnectionString = value;
					break;
				case "ConfigurationDALTableName":
					ConfigurationDALTableName = value;
					break;
				case "ConfigurationPartitionKey":
					ConfigurationPartitionKey = value;
					break;
				case "ConfigurationRoleRowKey":
					ConfigurationRoleRowKey = value;
					break;
				case "CounterSettingsTableName":
					CounterSettingsTableName = value;
					break;
				case "ControlledRoleName":
					ControlledRoleName = value;
					break;
				case "InstancesConnectionString":
					InstancesConnectionString = value;
					break;
				case "InstancesPartitionKey":
					InstancesPartitionKey = value;
					break;
				case "InstancesTableName":
					InstancesTableName = value;
					break;
				case "PerformanceCountersConnectionString":
					PerformanceCountersConnectionString = value;
					break;
				case "PerformanceCountersPartitionKey":
					PerformanceCountersPartitionKey = value;
					break;
				case "StateMachineConnectionString":
					StateMachineConnectionString = value;
					break;
				case "StateMachinePartitionKey":
					StateMachinePartitionKey = value;
					break;
				case "StateMachineTableName":
					StateMachineTableName = value;
					break;
				case "SubscriptionID":
					SubscriptionID = value;
					break;
				case "ThumbPrint":
					ThumbPrint = value;
					break;
				case "MaxInstances":
					MaxInstances = Int32.Parse(value);
					break;
				case "MinInstances":
					MinInstances = Int32.Parse(value);
					break;
				case "WADiagnosticConnectionString":
					WADiagnosticConnectionString = value;
					break;
				case "WADPerformanceCountersDALTableName":
					WADPerformanceCountersDALTableName = value;
					break;
			}
		}
	}
}